package com.util;
import it.sauronsoftware.jave.AudioAttributes;   
import it.sauronsoftware.jave.Encoder;  
import it.sauronsoftware.jave.EncoderException;  
import it.sauronsoftware.jave.EncodingAttributes;  
import it.sauronsoftware.jave.InputFormatException;  
import java.io.File; 
public class Audiotranscoding {
	public static void main(String[] args) throws Exception {  
        String path1 = "E:\\http___192.168.10.36_80_ssy_ccf_chatfiles";  
        String path2 = "E:\\test.pcm";  
        changeToPcm(path1, path2);  
    }  
  
    public static void changeToPcm(String sourcePath, String targetPath) {  
    	File source = new File(sourcePath);
    	File target = new File(targetPath);
    	AudioAttributes audio = new AudioAttributes();
    	audio.setCodec("pcm_s16le");
    	//比特率 比特率越高，音质就越好。
    	audio.setBitRate(new Integer(128000));
    	//1 单声道    2 立体声
    	audio.setChannels(new Integer(1));
    	//数据格式必须是采样率为8KHz或16KHz（本地识别只支持16K采样率，云端都支持）
    	audio.setSamplingRate(new Integer(16000));
    	EncodingAttributes attrs = new EncodingAttributes();
    	attrs.setFormat("wav");
    	attrs.setAudioAttributes(audio);
    	Encoder encoder = new Encoder();
  
        try {  
            encoder.encode(source, target, attrs);  
        } catch (IllegalArgumentException e) {  
            e.printStackTrace();  
        } catch (InputFormatException e) {  
            e.printStackTrace();  
        } catch (EncoderException e) {  
            e.printStackTrace();  
        }  
    }  

}
